package com.hfengxiang.example.canvasrotatedemo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class StarAdapter extends RecyclerView.Adapter<StarAdapter.StarHolder> {
    private List<Star> mDataSet;

    public StarAdapter(List<Star> mDataSet) {
        this.mDataSet = mDataSet;
    }

    @NonNull
    @Override
    public StarHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_item,null);
        return new StarHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull StarHolder holder, int position) {
        holder.textView.setText(mDataSet.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return mDataSet == null?0:mDataSet.size();
    }

    public static class StarHolder extends RecyclerView.ViewHolder {
        private TextView textView;
        public StarHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.text);
        }

        public TextView getTextView() {
            return textView;
        }
    }

    public boolean isHeaderView(int position){
        if(position == 0){
            return true;
        }else {
            String group = mDataSet.get(position).getGroup();
            String preGroup = mDataSet.get(position-1).getGroup();
            if(!group.equals(preGroup)){
                return true;
            }
            return false;
        }
    }

    public List<Star> getDataSet() {
        return mDataSet;
    }
}
